import java.util.Arrays;

class Solution {
    public long minimumTime(int[] time, int totalTrips) {
        int n = time.length;
        long left = 1, right = (long) totalTrips * time[0];
        
        while (left < right) {
            // mid 是时间
            long mid = left + (right - left) / 2;
            long trip = fun(mid, time);
            if (trip < totalTrips) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        return left;
    }
    // 计算在 mid 时间中能完成的旅途数
    private long fun(long mid, int[] time) {
        long trip = 0;
        for (int x : time) {
            trip += mid / x;
        }
        return trip;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] time = new int[]{9,3,10,5};
        System.out.println(solution.minimumTime(time, 2));
    }
}